<template>
  <div style="">
    <div class="class-header">
      <div class="class-background">
        <img src="../../../assets/images/student/confirm-order-bg.png" style="width: 100%">
        <div class="class-introduction">
          <div class="class-title">
            确认订单
          </div>
          <div class="tutor-info">
            <Card style="width:100%">
              <div style="text-align:left">
                <h3>商品信息</h3>
                <Row style="margin-top: 15px;margin-bottom: 15px;">
                  <i-col span="5">
                    <img class="img" :src="courseDetail.handcover"/>
                  </i-col>
                  <i-col span="15">
                    <h3>{{courseDetail.courseName}}</h3>
                  </i-col>
                  <i-col span="4">
                    <h3 style="color: #e13d13">￥{{courseDetail.price}}</h3>
                  </i-col>
                </Row>
                <hr>
                <div style="margin-top: 15px;text-align: right;line-height: 28px;">
                  <div>
                    <span>商品总金额:</span>
                    <span>￥{{courseDetail.price}}</span>
                  </div>
                  <div>
                    <span style="font-size: 18px;">应付</span>
                    <span style="font-size: 18px;color: #e13d13;font-weight: bold;">￥{{courseDetail.price}}</span>
                  </div>
                  <div style="margin-top: 15px;">
                    <Button type="error" @click="createOrder" style="font-size: 18px;width: 180px;">提交订单</Button>
                  </div>
                </div>
              </div>
            </Card>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'index',
  data () {
    return {
      courseDetail: {
        bgImage: '',
        chaptersListVOS: [],
        courseName: '',
        difficulty: '',
        handcover: '',
        id: '',
        introduction: '',
        labelId: '',
        labelNames: [],
        notice: '',
        orgName: '',
        price: 0,
        studentNumber: 0,
        teacherName: ''
      }
    }
  },
  methods: {
    getCourseDetail () {
      let url = '/api/api/student/course/detail'
      let params = {
        courseId: this.$route.query.courseId
      }
      this.$get(url, params).then((res) => {
        if (res.code === 0) {
          this.courseDetail = res.data
        }
      })
    },
    createOrder () {
      let url = '/api/order/create'
      let params = {
        courseId: this.$route.query.courseId,
        orderRemarks: this.courseDetail.courseName
      }
      this.$post(url, params).then((res) => {
        if (res.code === 0) {
          if (res.data.code === 20004) {
            this.message.error(res.data.errorMessage)
            return false
          }
          this.courseDetail = res.data
          this.$router.push({
            name: 'pay-confirm',
            query: {
              orderId: res.data
            }
          })
        }
      })
        .catch((error) => {
          console.log(error)
          if (error.status === 500) {
            const title = '登录提示'
            const content = '检测到您尚未登录，将跳转到登录页面！'
            this.$Modal.error({
              title: title,
              content: content,
              onOk: () => {
                this.headForLogin()
              }
            })
          }
        })
    },
    headForLogin () {
      this.$router.push('/index/login')
    }
  },
  mounted () {
    this.getCourseDetail()
  }
}
</script>

<style scoped>
  .class-background {
    position: relative;
  }
  .class-introduction {
    position: absolute;
    top: 20px;
    width: 100%;
    padding: 0 5%;
  }
  .class-title {
    margin-top: 1.5rem;
    font-size: 2rem;
  }
  .tutor-info {
    margin-top: 1.5rem;
  }
  .img{
    width: 300px;
    height: 200px;
  }
  .tutor-avatar {
    border-radius: 50%;
    width: 50px;
    float: left;
  }
  .tutor-name {
    margin-left: 70px;
  }
  .name-info {
    font-size: 16px;
    font-weight: bold;
  }
  .org-info {
    font-size: 12px;
  }
  .tutor-label {
    margin-left: 70px;
  }
  .class-live-status {
    margin-top: 4rem;
  }
  .share {
    margin-top: 2.5rem;
  }
  .share-button {
    font-size: 20px;
  }
  .class-content {
    width: 100%;
    margin-top: -5px;
  }
  .class-select-tab {
    height: 60px;
    background: white;
    box-shadow:2px 2px 3px rgba(238, 48, 48, 0.07);
  }
  .chapter-menu {
    padding: 0 5%;
    line-height: 60px;
  }
  .chapter-menu-item {
    margin-right: 1.8rem;
  }
  .chapters {
    padding: 0 5%;
  }
  .class-progress {
    padding: 15px;
    width: 100%;
    min-height: 22rem;
    background: #ffffff;
    border-radius: 15px;
    box-shadow:2px 2px 3px 3px #e9e9e9;
  }
  .class-progress-title {
    margin-top: 15px;
  }
  .class-progress-previous {
    font-size: 12px;
    text-align: center;
    margin-top: 5px;
  }
  .continue-study {
    margin-top: 15px;
    color: #ffffff;
    background: #e13d13;
    width: 100%;
    font-size: 20px;
    border-radius: 25px;
    height: 50px;
  }
  .chapter-title {
    font-size: 16px;
    font-weight: bold;
  }
  .chapter-subtitle {

  }
  .chapter-item {
    margin-top: 15px;
    height: 50px;
    width: 100%;
    line-height: 50px;
    padding: 0 8px;
  }
  .chapter a :hover {
    height: 50px;
    line-height: 50px;
    padding: 0 8px;
    color: #db2516;
    background: #fffcc8;
    border-radius: 5px;
  }
</style>
